import 'package:flutter/material.dart';

class ScaleBuiltTransition extends StatelessWidget {
  const ScaleBuiltTransition({
    super.key,
    required this.scale,
    required this.child,
  });

  final Animation<double> scale;
  final Widget child;

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: scale,
      child: child,
      builder: (context, child) {
        // The ImageFilter layer created by setting filterQuality will introduce
        // a saveLayer call. This is usually worthwhile when animating the layer,
        // but leaving it in the layer tree before the animation has started or after
        // it has finished significantly hurts performance.

        // TODO: [Impeller] enable filterQuality when it gets fixed
        // Now filterQuality changes transform scale origin

        // final bool useFilterQuality;
        //
        // switch (scale.status) {
        //   case AnimationStatus.dismissed:
        //   case AnimationStatus.completed:
        //     useFilterQuality = false;
        //     break;
        //   case AnimationStatus.forward:
        //   case AnimationStatus.reverse:
        //     useFilterQuality = true;
        //     break;
        // }

        return Transform.scale(
          scale: scale.value,
          alignment: Alignment.center,
          origin: Offset.zero,
          // filterQuality: useFilterQuality ? FilterQuality.medium : null,
          child: child,
        );
      },
    );
  }
}
